package com.foton.lotterydomain.rule.service.engine.impl;

import cn.hutool.core.util.ObjectUtil;
import com.foton.lotterydomain.rule.model.aggregates.TreeRuleRich;
import com.foton.lotterydomain.rule.model.req.DecisionMatterReq;
import com.foton.lotterydomain.rule.model.res.EngineResult;
import com.foton.lotterydomain.rule.model.vo.TreeNodeVO;
import com.foton.lotterydomain.rule.repository.IRuleEngineRepository;
import com.foton.lotterydomain.rule.service.engine.BaseEngine;
import com.foton.lotterydomain.strategy.service.algorithm.impl.BaseAlgorithm;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author RenPu
 * @Date 2024/1/4 17:54
 * @Version 1.0
 * @Description:
 **/

@Component
public class RuleEngineHandle  extends BaseEngine {

    @Resource
    private IRuleEngineRepository iRuleEngineRepository;

    @Override
    public EngineResult process(DecisionMatterReq matter) {

        TreeRuleRich treeRuleRich = iRuleEngineRepository.queryTreeRuleRich(matter.getTreeId());
        if(ObjectUtil.isEmpty(treeRuleRich)){
            throw new RuntimeException("Tree Rule is null!");
        }
        // 决策节点
        TreeNodeVO treeNodeInfo = engineDecisionMaker(treeRuleRich, matter);

        // 决策结果
        return new EngineResult(matter.getUserId(),treeNodeInfo.getTreeId(),treeNodeInfo.getTreeNodeId(),treeNodeInfo.getNodeValue());
    }
}
